﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace PFAGame
{
    class ProjectileTower : AProjectile
    {
        Texture2D tmpTex;
        float angle;

        public override void init()
        {
            base.init();
            obj = AObject.e_object.PROJECTILETOWER;
            tmpTex = ScreenManager.Singleton.Game.Content.Load<Texture2D>("rangedprojectile");

            angle = (float)Math.Acos(orientation.X);
            if (orientation.Y < 0)
                angle = -angle;
        }

        public override void update(GameTime gameTime)
        {
            // deplacement dans AProjectile
            base.update(gameTime);

            // SphereCast pour tester les collision sur la liste de mob (projectile de joueur)
            List<AObject> list = AObject.SphereCast(position + orientation * 0.25f, 0.25f, GameplayScreen.Singleton.Players);
            if (list.Count != 0)
            {
                // si un objet est touché, on applique les dégats et on détruit le projectile
                foreach (APlayer player in list)
                    player.receiveDammage(Dammage);
                GameplayScreen.Singleton.DeleteProjectileList.Add(this);
            }

        }

        public override void draw(GameTime gameTime, Camera camera)
        {
            base.draw(gameTime, camera);
            displayRectangle.X += camera.ZoomLevel / 2;
            displayRectangle.Y += camera.ZoomLevel / 2;
            ScreenManager.Singleton.SpriteBatch.Draw(tmpTex, displayRectangle, new Rectangle(0, 0, 64, 64), Color.White, angle, new Vector2(32, 32), SpriteEffects.None, 0);
        }
    }
}
